const {data,userList} =require('./mock')
const bodyParser=require('body-parser')

module.exports=app=>{
    app.use(bodyParser.json())
    app.post('/api/list',(req,res)=>{
        let {keys,page}=req.body
        const newData=data.filter(item=>item.status===keys*1)
        res.send({
            code:200,
            total:newData.length,
            data:newData.filter((v,i)=>i<page*10)
        })
    })
    app.post('/api/login',(req,res)=>{
        const {username,password}=req.body
        const users=userList.find(item=>item.username===username&&item.password===password)
        if(users){
            res.send({
                code:200,
                mes:'登录成功',
                data:users.username
            })
        }else{
            res.send({
                code:400,
                mes:'账号密码有误'
            })
        }
    })
}